<!DOCTYPE html>
<html>

	<head lang="en">
		<title>游记评论详情</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<!--<script src="/js/loginIntercept.js"></script>-->
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/myStrategyComment.css"/>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/common.js"></script>
		<script src="/js/checkLogin.js"></script>
	</head>

	<script>
		$(function(){
			var num;//定义星星的点击数量
			//处理星星的点击事件
			$(".star i").click(function(){
				//获取点击星星的数量
				num = $(this).data("num");
				//获取所有的星星
				var arr = $(".star i");
				//清空所有星星的样式
				$(arr).removeClass("fa-star").addClass("fa-star-o");
				//遍历选中星星,修改其样式
				for(var i = 0;i<num;i++){
					$(arr[i]).removeClass("fa-star-o").addClass("fa-star");
				}
			});

			//定义全局的图片div变量
			var div;
			//图片上传功能
			$(".imgs .rect").click(function(){
				div = this;
				$("#fileUpload").click();
			});
			$("#fileUpload").change(function(){
				if (this.value) {
					$("#fileForm").ajaxSubmit({
						url:baseUrl+"/images",
						success:function(data){
							console.log(data);
							if (data.status == 1) {
                                $(div).html('<img src="'+data.url+'">');
                            }
						}
					});
                }
			});

			var strategyId = getParams().id;
			//提交评价按钮的点击事件
			$("#submitBtn").click(function(){
				if (!num >= 1) {
					$(document).dialog({
						content: "请对该旅游进行评星",
						style: 'ios'
					});
					return;
                }
				if (strategyId) {
					//使用ajax提交评价的数据
					/**
					 * 提交评价接口的设计
					 * 资源:/strategies/{strategyid}/comments
					 * 请求方式:post
					 * 请求参数:json
					 * 返回值:JSONResult
					 */
					//定义标签数组
					var tagsArr = [];
					//系统评价的标签
					var arr = $(".active input");
					for(var i=0;i<arr.length;i++){
						tagsArr.push($(arr[i]).val());
					};
					//获取自定义的标签
					var myTag = $("#myTags").val();
					var myTagArr = myTag.split(" ");
					if (myTagArr.length) {
						for(var i=0;i<myTagArr.length;i++){
							var value=myTagArr[i];
							if (value != "") {
								tagsArr.push(myTagArr[i]);
                            }
						}
                    }
					//获取上传图片的地址
					var imgsArr = $(".imgs .rect img")
					//定义一个存放图片的变量
					var imgUrls = "";
					for(var i=0;i<imgsArr.length;i++){
						imgUrls += $(imgsArr[i]).attr("src")+";";
					}
					var json = {
						//星星的数量
						starNum: num,
						//提交的标签
						tags:tagsArr,
						//评价的内容
						content:$("#content").val(),
						//评价图片
						imgUrls:imgUrls
					};
					$.ajax({
						url: baseUrl + "/strategies/" + strategyId + "/comments",
						data: json,
						type: "post",
						success: function (data) {
							location.href="/strategyCatalogs.html?id="+strategyId;
						}
					});
				}
			});
			if (strategyId) {
				$.get(baseUrl + "/strategies/"+strategyId+"/tags",function(data){
					$(".btn-group-toggle").html();
					var tags = '';
					for(var i=0;i<data.length;i++){
						tags+='<label class="btn btn-outline-danger"><input type="checkbox" autocomplete="off" value="'+data[i].name+'">'+data[i].name+'</label>';
					}
					$(".btn-group-toggle").html(tags);
				});
			}
		});
	</script>

	<body style="background: url('/upload/2.bmp')">
	<form id="fileForm" enctype="multipart/form-data" method="post">
		<input type="file" id="fileUpload" name="file" hidden>
	</form>

	<div class="search-head">
		<div class="row nav-search">
			<div class="col">
				<a href="javascript:window.history.go(-1)">
					<span><i class="fa fa-chevron-left" ></i></span>
				</a>

			</div>
			<div class="col">
				<span>点评</span>
			</div>
			<div class="col"></div>
		</div>
	</div>

	<div class="comment">
		<div class="container star">
			<p>你对该旅游地的评价</p>
			<i class="fa fa-star-o fa-lg" data-num="1"></i>
			<i class="fa fa-star-o fa-lg" data-num="2"></i>
			<i class="fa fa-star-o fa-lg" data-num="3"></i>
			<i class="fa fa-star-o fa-lg" data-num="4"></i>
			<i class="fa fa-star-o fa-lg" data-num="5"></i>
		</div>
		<hr />
		<div class="container tag">
			<p>请为该旅游地选择合适的标签（大家都在评）</p>
			<div class="btn-group-toggle" data-toggle="buttons">
				<!--<label class="btn btn-outline-danger">
					<input type="checkbox" autocomplete="off" value="价格便宜"> 价格便宜
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox" autocomplete="off" value="住宿方便"> 住宿方便
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox" autocomplete="off" value="旅游景点多"> 旅游景点多
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox" autocomplete="off" value="适合拍照">适合拍照
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox"  autocomplete="off" value="吃的很多">吃的很多
				</label>
				<label class="btn btn-outline-danger">
					<input type="checkbox"  autocomplete="off" value="交通不方便">交通不方便
				</label>-->
			</div>

			<p>添加你自己的标签</p>
			<input id="myTags" class="form-control"  placeholder="请使用空格隔开标签，每个标签不超8个字"   />

			<p>更多评价内容</p>
			<textarea id="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
		</div>
		<div class="container imgs">
			<p>上传图片</p>

			<div class="row">
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
				<div class="col-3 rect">
					<span>上传</span>
				</div>
			</div>
		</div>

	</div>



	<div class="operation">
		<button class="btn" onclick="window.history.go(-1)">放弃评价</button><button class="btn" id="submitBtn">提交评价</button>
	</div>





	</body>


</html>